//
//  XJComposePictureView.swift
//  XJWeiBO
//
//  Created by 452608533 on 16/7/26.
//  Copyright © 2016年 452608533. All rights reserved.
//

import UIKit

class XJComposePictureView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI() {
        backgroundColor = UIColor.whiteColor()
        
        registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
        
        let cellMargin : CGFloat = 5
        let cellW = (SCREENW - 20 - cellMargin*2)/3
        
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: cellW, height: cellW)
        layout.minimumInteritemSpacing = 5
        layout.minimumLineSpacing = 5
        
        dataSource = self
    }
}
extension XJComposePictureView: UICollectionViewDataSource{
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 9
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath)
        cell.backgroundColor = RandomColor()
        return cell
    }
}